package xyz.chaobei.gateway.initializer;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpContentEncoder;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import xyz.chaobei.gateway.inbound.HttpInboundHandler;

public class HttpInitializer extends ChannelInitializer<SocketChannel> {

    private String proxy;

    public HttpInitializer(String proxy) {
        this.proxy = proxy;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024));

        pipeline.addLast(new HttpInboundHandler(this.proxy));
    }
}
